// src/mixins/shortcut.js
import { TakeScreenshot } from '../../wailsjs/go/controller/screenApp'

export default {
  mounted() {
    window.addEventListener('keydown', this.handleGlobalKeyDown)
  },
  beforeDestroy() {
    window.removeEventListener('keydown', this.handleGlobalKeyDown)
  },
  methods: {
    async handleGlobalKeyDown(e) {
      if (e.altKey && e.key.toLowerCase() === 'w') {
        e.preventDefault()
        try {
          const path = await TakeScreenshot()
          this.$notify({
            title: '截图成功',
            message: `截图已保存到: ${path}`,
            type: 'success'
          })
        } catch (error) {
          this.$notify.error({
            title: '截图失败',
            message: error.message
          })
        }
      }
    }
  }
}